﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Domain;
using Persistence.Dao;
using Persistence;
using Common;
namespace web.manage
{
    public partial class member_manage : adminBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindList();
            }
        }

        private void BindList()
        {
            string what = "*";
            string where = "1=1";
            string orderBy = "userid desc";
            IList<User> list = Singleton<UserDao>.Instance.GetModels(what, where, orderBy, anp.PageSize, anp.CurrentPageIndex);
            if (list.Count > 0)
            {
                rptList.Visible = true;
                rptList.DataSource = list;
                rptList.DataBind();
            }
            else
            {
                rptList.Visible = false;
            }
        }
        protected void anp_PageChanged(object sender, EventArgs e)
        {
            BindList();
        }
        protected void rptList_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "deleteUser")
            {
                bool bResult = false;
                System.Int32 ID = 0;
                if (System.Int32.TryParse(e.CommandArgument.ToString(), out ID))
                {
                    Domain.User u = new User();
                    u.userId = ID;
                    bResult = Singleton<UserDao>.Instance.Delete(u);
                }
                if (bResult)
                {
                    Message.alert("操作成功");
                    BindList();
                }
                else
                {
                    Message.alert("操作失败，请检查您的数据");
                }
            }
        }
    }
}
